package org.dubnation;

import org.dubnation.base.interceptors.AuthenticInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@MapperScan("org.dubnation.*.mapper")
//@ServletComponentScan("org.dubnation.base.listener")  //扫描监听器
public class PermissionStarter implements WebMvcConfigurer {
    public static void main(String[] args) {
        SpringApplication.run(PermissionStarter.class, args);
    }

    @Autowired
    private AuthenticInterceptor interceptor;
    /* 添加拦截器 */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptor)
                .addPathPatterns("/**")  //拦截所有层级的请求，使请求走拦截器
                .excludePathPatterns("/login","/logout"); //放行登录和登出请求，不走拦截器
    }
}
